package com.framework.modules.base.service.impl;

import com.framework.common.utils.*;
import com.framework.modules.common.service.IPayChannel4OtherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import com.framework.modules.base.dao.UserOrderDao;
import com.framework.modules.base.entity.UserOrderEntity;
import com.framework.modules.base.service.UserOrderService;
import org.springframework.transaction.annotation.Transactional;

@DependsOn("databaseInitConfig")
@Service("userOrderService")
public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrderEntity> implements UserOrderService {

    @Autowired
    private IPayChannel4OtherService payChannel4OtherService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        EntityWrapper wrapper=new EntityWrapper<UserOrderEntity>();
        if(params.containsKey("uid")){
            wrapper.eq("uid",params.get("uid"));
        }
        Page<UserOrderEntity> page = this.selectPage(
                new Query<UserOrderEntity>(params).getPage(),
                wrapper
        );

        return new PageUtils(page);
    }
    @Transactional
    @Override
    public Object recharge(UserOrderEntity orderEntity) {
        // 1.生成订单号
        String orderid=BizSequenceUtils.getInstance().generateBizSeqNo("YJ");
        orderEntity.setId(orderid);
        orderEntity.setAdddate(DateUtils.getSecondTimestamp(new Date()));
        // 2.插入订单表
        if(this.baseMapper.insert(orderEntity)<1){
            return "系统错误，请重试";
        }
        Object object="下单失败";
        //3.判断支付渠道
        switch (orderEntity.getPeymentType()){
            case "alipay":break;
            case "weixin":break;
            case "other":
                object=payChannel4OtherService.doOtherPayWapReq(orderEntity);
                break;
            default:;
        }
        return object;
    }

}
